/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       bitmap_layer_cache.h

	$Header: /game/bitmap_layer_cache.h $

	$NoKeywords: $

 ************************************************************************/

#ifndef BITMAP_LAYER_CACHE_H_INCLUDED
#define BITMAP_LAYER_CACHE_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <string>

#include "bitmap_group_ptr.h"
#include "cached_ptr.h"

// ---------------------------------------------------------------------------------------
// cache to reference a single layer in a bitmap group, which is loaded from another cache
// ---------------------------------------------------------------------------------------
class t_bitmap_layer;

class t_bitmap_layer_cache_data : public t_abstract_cache_data<t_bitmap_layer>
{
public:
	typedef t_abstract_cache<t_bitmap_group> t_source_cache;

	t_bitmap_layer_cache_data( t_source_cache const& source, std::string const& name );

	std::string get_name() const;
protected:
	virtual void            add_reference();
	virtual t_bitmap_layer* do_get( t_progress_handler* handler );
	virtual void            remove_reference();

	t_source_cache		m_source;
	std::string         m_name;
	t_bitmap_group_ptr	m_bitmaps;
	int                 m_index;
	int					m_reference_count;
	t_bitmap_layer*     m_data;
};

inline std::string t_bitmap_layer_cache_data::get_name() const
{
	return m_name;
}

class t_bitmap_layer_cache : public t_abstract_cache<t_bitmap_layer>
{
public:
	typedef t_abstract_cache<t_bitmap_group> t_source_cache;

	t_bitmap_layer_cache( t_source_cache const& source, std::string const& name );

	std::string get_name() const;
private:
	t_bitmap_layer_cache_data* m_data;
};

inline t_bitmap_layer_cache::t_bitmap_layer_cache( t_source_cache const& source, 
												   std::string const& name )
						   : t_abstract_cache<t_bitmap_layer>( 0 )
{
	m_data = new t_bitmap_layer_cache_data( source, name );
	set( m_data );
}

inline std::string t_bitmap_layer_cache::get_name() const
{
	return m_data->get_name();
}

#endif // BITMAP_LAYER_CACHE_H_INCLUDED